import 'dart:html';
import 'dart:io';

import 'package:dio/adapter.dart';
import 'package:dio/dio.dart';

Future<void> main() async {
  Dio dio = Dio();
  /// Get

  Response response;
  response  = await dio.get("https://www.baidu.com?id=13&name=lark");
  print(response.data.toString());

  response  = await dio.get("https://www.baidu.com", queryParameters:{"id":13,"name":"lark"});
  print(response.data.toString());

  /// Post
  response  = await dio.post("https://www.baidu.com", data: {"id":12,"name":"lark"});
  print(response);

  /// multiple request
  response = (await Future.wait([
    dio.post("/info"),
    dio.get("/token")
  ])) as Response;

  /// download file
  response = await dio.download("https://www.baidu.com", "sava Path");

  /// formData request

  FormData formData = FormData.fromMap({
    "name":"lark",
    "age":"25"
  });
  response = await dio.post("/data", data: formData);

  /// certificate
  HttpClient httpClient = HttpClient();
  (dio.httpClientAdapter as DefaultHttpClientAdapter).onHttpClientCreate = (client) {
    //设置代理
    client.findProxy = (uri) {
      return "PROXY 192.168.1.2:8888";
    };
    //校验证书
    httpClient.badCertificateCallback=(X509Certificate cert, String host, int port){
      // if(cert.pem== PEM){
      if(cert.pem== cert){
        return true; //证书一致，则允许发送数据
      }
      return false;
    };
  };


}